import { ss } from '@/utils/storage'

const LOCAL_NAME = 'SECRET_TOKEN'

const Authorization_Token_name = 'AUTHORIZATION_TOKEN'

const TOKEN_EXPIRATION_TIME = 'TOKEN_EXPIRATION_TIME'

const USER_ID = 'USERID'

export function getToken() {
  return ss.get(LOCAL_NAME)
}

export function setToken(token: string) {
  return ss.set(LOCAL_NAME, token)
}

export function removeToken() {
  return ss.remove(LOCAL_NAME)
}

// 授权token
export function getAuthorizationToken() {
  return ss.get(Authorization_Token_name)
}

export function setAuthorizationToken(token: string) {
  return ss.set(Authorization_Token_name, token)
}

export function removeAuthorizationToken() {
  return ss.remove(Authorization_Token_name)
}

// token过期时间
export function getTokenExpirationTime() {
  return ss.get(TOKEN_EXPIRATION_TIME)
}

export function setTokenExpirationTime(time: string) {
  return ss.set(TOKEN_EXPIRATION_TIME, time)
}

export function removeTokenExpirationTime() {
  return ss.remove(TOKEN_EXPIRATION_TIME)
}

// userId
export function getUserId() {
  return ss.get(USER_ID)
}

export function setUserId(userId: string) {
  return ss.set(USER_ID, userId)
}

export function removeUserId() {
  return ss.remove(USER_ID)
}

export function setLoginMode(mode: 'default' | 'dingtalk') {
  ss.set('LOGIN_MODE', mode)
}

export function getLoginMode(): 'default' | 'dingtalk' {
  const mode = ss.get('LOGIN_MODE')
  switch (mode) {
    case 'dingtalk':
      return mode
    default:
      return 'default'
  }
}

export function resetLoginMode() {
  return ss.remove('LOGIN_MODE')
}
